-- A Gwee example
-- Author: Michael Carius <michael.a.carius@gmail.com>

local gwee = require "gwee"

function love.load()
    love.graphics.setColor(0xff, 0xff, 0xff, 0xff)
    love.graphics.setFont(12)

    -- track button clicks
    numClicks = 0

    -- basic widget group
    group1 = gwee.Group(gwee.Box(100, 100, 100, 100), gwee.VerticalLayout(5),
        "Basic")
    group1:add(gwee.Button(function() numClicks = numClicks + 1 end, "Button"))
    group1.textfield = group1:add(gwee.TextField("TextField:"))
    group1.checkbox = group1:add(gwee.CheckBox("CheckBox:"))
    group1.slider = group1:add(gwee.Slider(0, 100, "Slider:"))

    -- skinned widget group
    group2 = gwee.Group(gwee.Box(300, 100, 100, 100), gwee.VerticalLayout(5),
        "Skinned", gwee.loadSkin("treesap"))
    group2:add(gwee.Button(function() end, "Button"))
    group2.textfield = group2:add(gwee.TextField("TextField:"))
    group2.checkbox = group2:add(gwee.CheckBox("CheckBox:"))
    group2.slider = group2:add(gwee.Slider(0, 100, "Slider:"))

    -- controls enable/disable
    control = gwee.Group(gwee.Box(500, 100, 100, 100), gwee.VerticalLayout(5),
        "Enable/Disable")
    control:add(gwee.Button(function() group1.enabled = not group1.enabled end,
        "Group 1"))
    control:add(gwee.Button(function() group2.enabled = not group2.enabled end,
        "Group 2"))
end

function love.keypressed(key, unicode)
    gwee.keypressed(key, unicode)
end

function love.mousepressed(x, y, button)
    gwee.mousepressed(x, y, button)
end

function love.mousereleased(x, y, button)
    gwee.mousereleased(x, y, button)
end

function love.update(dt)
    gwee.update(dt)
end

function love.draw()
    gwee.draw()
    love.graphics.print("Button has been clicked " .. numClicks .. " times",
        0, 0)
    love.graphics.print("TextField contains: " .. group1.textfield.text, 0, 15)
    love.graphics.print("CheckBox is checked: "
        .. tostring(group1.checkbox.checked), 0, 30)
    love.graphics.print("Slider value: " .. group1.slider.value, 0, 45)
end
